package org.safaproject.server.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.safaproject.server.model.MoldeTag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Transactional;

@Transactional(rollbackFor=Exception.class)
public class MoldeTagDAO extends HibernateDaoSupport{
	
	@Autowired
	public void initSessionFactory(SessionFactory factory) {
	    setSessionFactory(factory);
	}
	
	public MoldeTag getMoldeTagById(String nombreTag){
		return (MoldeTag) super.getHibernateTemplate().load(MoldeTag.class, nombreTag);
	}
	
	@SuppressWarnings("unchecked")
	public List<MoldeTag> getAllMoldeTags(){
		return super.getHibernateTemplate().find("from MoldeTag");
	}
	
	public String saveMoldeTag(MoldeTag moldeTag){
		super.getHibernateTemplate().save(moldeTag);
		return moldeTag.getNombreTag();
	}
	
	public String updateMoldeTag(MoldeTag moldeTag){
		super.getHibernateTemplate().update(moldeTag);
		return moldeTag.getNombreTag();
	}

}
